package com.jianyun.jyzs.http;


import android.util.Log;

import com.jianyun.jyzs.bean.IndustryResponse;

import java.util.HashMap;
import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by mlli on 2017/11/21.
 * 获取所属行业
 */

public class IndustryHelper {
    public interface IndustryListener {
        void getIndustrySuccess(List<IndustryResponse.IndustryBean> list);

        void getIndustryFail(String msg);
    }

    public static void getIndestry(String enterpriseCode, final IndustryListener listener) {
//        HashMap<String, String> map = new HashMap<>();
//        map.put("enterpriseCode", enterpriseCode);
//        Api api = RetrofitHelper.builderbch().create(Api.class);
//        api.getIndustry(map)
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribeOn(Schedulers.io())
//                .subscribe(new CustomCallback<IndustryResponse>() {
//                    @Override
//                    protected void onResponse(IndustryResponse response) {
//                        if (response.isResult()) {
//                            if (listener != null) listener.getIndustrySuccess(response.getList());
//                        } else {
//                            if (listener != null) listener.getIndustryFail(response.getMessage());
//                        }
//                    }
//
//                    @Override
//                    protected void onException(String msg) {
//                        if (listener != null) listener.getIndustryFail(msg);
//                    }
//                });
    }

    /**
     * 新的获取所属行业
     *
     * @param enterpriseCode
     */
    public static void getNewIndestry(String enterpriseCode,final IndustryListener listener) {
        HashMap<String, String> map = new HashMap<>();
        map.put("method", "crm_sshy");
        map.put("enterpriseCode",enterpriseCode);
        map.put("appCode","jyzs");
        map.put("appType","Android");
        map.put("appVersion","1.0.2");
        Api api = RetrofitHelper.builderErpRoot().create(Api.class);
        api.getNewIndustry(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<IndustryResponse>() {
                    @Override
                    protected void onResponse(IndustryResponse response) {
                        if (response.isResult()) {
                            if (listener != null) listener.getIndustrySuccess(response.getData());
                        } else {
                            if (listener != null) listener.getIndustryFail(response.getMessage());
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                        if (listener != null) listener.getIndustryFail(msg);
                    }
                });
    }
}
